<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="m" uri="/cutm_tags"%>

<html>
<head>
<title>撰写稿件</title>

<script type="text/javascript" src="<s:url value="/manuscript/focos.js" />"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	if($('input[name="readOnly"]').val()!=''){
		BaseJs.setReadonly();
		$('.btnGroup').remove();
	}
	$("#myform").vaildAjax(function(data){
		$('input[name="manuscript.id"]').val(data);
		BaseJs.alert('操作成功!');
		//BaseJs.setReadonly();
	});
	
	var options = {selectAllText: '全选',noneSelected:'请选择联合报道记者',oneOrMoreSelected:'已选%人',listHeight:'200'};
	$('#selectType').multiSelect(options,function(){
		$('input[name="lhjz"]').val($('input[class=selectType]').checkbox());
	});
	$('input[name="lhjz"]').val($('input[name="lhbdjzId"]').val());		
	//$('.sub').click(function(){
		//	alert($('#vido').val());
			// $("#myform").submit();
	//	});
	$('a.delimage').live('click',function(){
		var id = $($(this)[0]).attr('value');
		var mid = $('input[name="manuscript.id"]').val();
		$.urlAjax('manuscript/EditManuscript!delRefrence?images='+id+'&manuscript.id='+mid,function(data){
			if(data=='OK'){
				$('#li'+id).remove();
				BaseJs.alert('删除成功.');
			}
		});
	});
	
	$('a.viewBig').click(function(e,obj){
		var ori = $($(this)[0].parentNode.innerHTML).find('img')[0].src;
		var now = ori.replace('_128.','.');
		window.open(now);
	});
});

function getFullPath(obj) 
{ 
    if(obj) 
    { 
        if (window.navigator.userAgent.indexOf("MSIE")>=1) 
        { 
            obj.select();
            return document.selection.createRange().text; 
        } 
        else if(window.navigator.userAgent.indexOf("Firefox")>=1) 
        { 
            if(obj.file) 
            { 
                alert(obj.files.item(0).getAsDataURL());
                return obj.files.item(0).getAsDataURL(); 
            } 
            return obj.value; 
        } 
        return obj.value; 
    } 
} 

function checkSubAudit(){
	var id=$('input[name="manuscript.id"]').val();
	if(id==''){
		alert("请先上传保存稿件!");
		return false;
	}
	if(BaseJs.confirm('确定提交审核吗？提交审核后,在未审核前您不能编辑稿件!')){
		$.urlAjax('manuscript/EditManuscript!subAudit?manuscript.id='+id,function(data){
			if(data!=''){
				$.alert('提交成功');
				$('#sub2').remove();
				$('#sub1').remove();
				//BaseJs.toAction('manuscript/ListManuscript');
			}
		});

	}
}

function addImage2Mscript(){
    $.fn.jmodal({
    	title:'上传文件窗口',
    	buttonText : '上传完成',
    	okEvent:function(e){},
        content: '<iframe scrolling="no" height="80px" frameborder="no" border="0" marginwidth="0" marginheight="0"  allowtransparency="yes" src="<s:url value="/upload/ToLoad.action" />" ></iframe>'
     });
}

//添加文件刀
function addImg2LiAndCloseWind(path){
	var all = path.split('_#_');
	$('#mimages').val($('#mimages').val()+','+all[0]);
	$('#allImagesArea').append(
			['<li id="li'+all[0]+'">',
               		'<div style="position:relative">',
              			'<div><a value="'+all[0]+'" class="delimage" href="##">删除</a></div>',
              			'<div>描述：'+all[1]+'</div>',
              			'<a class="viewBig" title="新窗口中，查看大图"><img src="'+BaseJs.root+'common/upload'+all[2]+'" width="180px" /></a>',
               		'</div></li>'].join(''));
}

</script>
<style type="text/css">
#allReporters p {
	margin: 2px auto 1px 2px;
}
</style>
</head>
<body>
<h2 class="title">稿件信息</h2>
<s:form id="myform" action="manuscript/EditManuscript" method="post">
	<s:hidden name="manuscript.id" />
	<s:hidden name="lhbdjzName" />
	<s:hidden name="lhbdjzId" />
	<s:hidden name="readOnly" />
	<s:hidden id="mimages" name="images" />
	<table class="form">
		<tr>
			<th width="10%"><span class="hint">*</span>标题</th>
			<td width="25%"><s:textfield name="manuscript.title" cssClass="rule[required]" cssStyle="width:250" /></td>
			<th width="10%"><span class="hint">*</span>是否急稿</th>
			<td width="15%"><s:radio list='#{ false:"否", true:"是"}' value="false" name="manuscript.urgent" /></td>
			<th width="10%"><span class="hint">*</span>所属栏目</th>
			<td width="15%"><m:select enumType="program.type" name="manuscript.column" /></td>
			<td width="15%">新闻相关图片 <m:imgA img="imageplus" msg="添加图片" onclick="javascript:addImage2Mscript();" /></td>
		</tr>
		<tr>
			<th><span class="hint">*</span>关键字：(,隔开)</th>
			<td><s:textfield name="manuscript.tags" maxLength="255"></s:textfield></td>
			<th><span class="hint">*</span>题材类别</th>
			<td><m:select enumType="submatter.typet" name="manuscript.owetype" /></td>
			<th><span class="hint">*</span>所属地域</th>
			<td><m:select enumType="region.type" name="manuscript.where" /></td>
			<td rowspan="5" valign="top" style="padding-left: 0; overflow: scroll; height: 500px;">
			<ul id="allImagesArea" style="margin: 0pt; padding: 0pt;">
				<s:iterator value="allimages">
					<li id="li${imageId}">
					<div style="position: relative">
					<s:if test="readOnly==null">
						<div><a value="${imageId}" class="delimage" href="##">删除</a></div>
					</s:if>
					<div>描述：${mark}</div>
					<a class="viewBig" title="新窗口中，查看大图"><img src="${path}" width="180px" /></a></div>
					</li>
				</s:iterator>
			</ul>
			</td>
		</tr>
		<tr>
			<th>报道单位</th>
			<td><m:select enumType="newsFrom.type" name="manuscript.unit" /></td>
			<th>来源描述</th>
			<td><s:textfield name="manuscript.remark" cssStyle="width:250" /></td>
			<th>联合撰稿记者</th>
			<td id="reporters"><s:hidden name="lhjz" />
			<select id="selectType" multiple="multiple" size="5" style="width: 100px;">
				<optgroup label="记者列表">
					<s:iterator value="allRepUser">
						<option id="op${id}" <m:ms name="lhbdjzId" value="${id}">selected</m:ms> value="${id}"><s:property value="name" /></option>
					</s:iterator>
				</optgroup>
			</select><s:property value="lhbdjz" escape="false" /></td>
		</tr>
		<tr>
			<th>加入公共稿库</th>
			<td colspan="3"><s:checkbox name="manuscript.is2Public" value="true" />(勾选加入，不勾选不加入),加入库可以使其他系统调用此稿件</td>
			<th>*上级审核人员</th>
			<td id="auditusers"><s:select list="users" name="manuscript.auditUser.id" label="审核人员列表" listKey="key"
				listValue="value" value="manuscript.auditUser.id"></s:select></td>
		</tr>
		<tr>
			<th>稿件备注</th>
			<td colspan="5"><s:textarea name="manuscript.comment" cssClass="rule[length[0,1000]]"></s:textarea></td>
		</tr>
		<tr>
			<td colspan="6"><s:textarea name="manuscript.content" id="ctt" cssClass="rule[required]"
				cssStyle="height: 400px;  width:  96%;"></s:textarea></td>
		</tr>
	</table> 
	<div class="btnGroup">
		<input type="submit" class="sub" value="保存稿件" id="sub1" />
		<input type="button" id="sub2" value="提交审核" onclick="checkSubAudit()" />
	
	</div>
</s:form>
</body>
</html>